home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
dlap.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-07-09
|
20KB
|
536 lines
;;;-*-Mode:LISP; Package:(PCL LISP 1000); Base:10; Syntax:Common-lisp -*-
;;;
;;; *************************************************************************
;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
;;; All rights reserved.
;;;
;;; Use and copying of this software and preparation of derivative works
;;; based upon this software are permitted. Any distribution of this
;;; software or derivative works must comply with all applicable United
;;; States export control laws.
;;;
;;; This software is made available AS IS, and Xerox Corporation makes no
;;; warranty about the software, its performance or its conformity to any
;;; specification.
;;;
;;; Any person obtaining a copy of this software is requested to send their
;;; name and post office or electronic mail address to:
;;; CommonLoops Coordinator
;;; Xerox PARC
;;; 3333 Coyote Hill Rd.
;;; Palo Alto, CA 94304
;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
;;;
;;; Suggestions, comments and requests for improvements are also welcome.
;;; *************************************************************************
;;;
(in-package 'pcl)
(defun emit-one-class-reader (class-slot-p) (emit-reader/writer :reader 1 class-slot-p))
(defun emit-one-class-writer (class-slot-p) (emit-reader/writer :writer 1 class-slot-p))
(defun emit-two-class-reader (class-slot-p) (emit-reader/writer :reader 2 class-slot-p))
(defun emit-two-class-writer (class-slot-p) (emit-reader/writer :writer 2 class-slot-p))
(defun emit-reader/writer (reader/writer 1-or-2-class class-slot-p)
(declare (type index 1-or-2-class)
(type boolean class-slot-p))
(let ((instance nil)
(arglist ())
(closure-variables ())
(field (first-wrapper-cache-number-index))) ;we need some field to do
;the fast obsolete check
(ecase reader/writer
(:reader (setq instance (dfun-arg-symbol 0)
arglist (list instance)))
(:writer (setq instance (dfun-arg-symbol 1)
arglist (list (dfun-arg-symbol 0) instance))))
(ecase 1-or-2-class
(1 (setq closure-variables '(wrapper-0 index miss-fn)))
(2 (setq closure-variables '(wrapper-0 wrapper-1 index miss-fn))))
(generating-lap closure-variables
arglist
(with-lap-registers ((inst t) ;reg for the instance
(wrapper #-structure-wrapper vector ;reg for the wrapper
#+structure-wrapper t)
#+structure-wrapper (cnv fixnum-vector)
(cache-no index)) ;reg for the cache no
(let ((index cache-no) ;This register is used
;for different values at
;different times.
(slots (and (null class-slot-p)
(allocate-register 'vector)))
(csv (and class-slot-p
(allocate-register t))))
(prog1 (flatten-lap
(opcode :move (operand :arg instance) inst) ;get the instance
(opcode :std-instance-p inst 'std-instance) ;if not either std-inst
(opcode :fsc-instance-p inst 'fsc-instance) ;or fsc-instance then
#+pcl-user-instances
(opcode :user-instance-p inst 'user-instance) ;if not either std-inst
(opcode :go 'trap) ;we lose
#+pcl-user-instances
(opcode :label 'user-instance)
#+pcl-user-instances
(opcode :move (operand :user-wrapper inst) wrapper)
#+pcl-user-instances
(and slots
(opcode :move (operand :user-slots inst) slots))
#+pcl-user-instances
(opcode :go 'have-wrapper)
(opcode :label 'fsc-instance)
(opcode :move (operand :fsc-wrapper inst) wrapper)
(and slots
(opcode :move (operand :fsc-slots inst) slots))
(opcode :go 'have-wrapper)
(opcode :label 'std-instance)
(opcode :move (operand :std-wrapper inst) wrapper)
(and slots
(opcode :move (operand :std-slots inst) slots))
(opcode :label 'have-wrapper)
#-structure-wrapper
(opcode :move (operand :cref wrapper field) cache-no)
#+structure-wrapper
(opcode :move (emit-wrapper-cache-number-vector wrapper) cnv)
#+structure-wrapper
(opcode :move (operand :cref cnv field) cache-no)
(opcode :izerop cache-no 'trap) ;obsolete wrapper?
(ecase 1-or-2-class
(1 (emit-check-1-class-wrapper wrapper 'wrapper-0 'trap))
(2 (emit-check-2-class-wrapper wrapper 'wrapper-0 'wrapper-1 'trap)))
(if class-slot-p
(flatten-lap
(opcode :move (operand :cvar 'index) csv)
(ecase reader/writer
(:reader (emit-get-class-slot csv 'trap inst))
(:writer (emit-set-class-slot csv (car arglist) inst))))
(flatten-lap
(opcode :move (operand :cvar 'index) index)
(ecase reader/writer
(:reader (emit-get-slot slots index 'trap inst))
(:writer (emit-set-slot slots index (car arglist) inst)))))
(opcode :label 'trap)
(emit-miss 'miss-fn))
(when slots (deallocate-register slots))
(when csv (deallocate-register csv))))))))
(defun emit-one-index-readers (class-slot-p)
(declare (type boolean class-slot-p))
(let ((arglist (list (dfun-arg-symbol 0))))
(generating-lap '(field cache-vector mask size index miss-fn)
arglist
(with-lap-registers ((slots vector))
(emit-dlap arglist
'(standard-instance)
'trap
(with-lap-registers ((index index))
(flatten-lap
(opcode :move (operand :cvar 'index) index)
(if class-slot-p
(emit-get-class-slot index 'trap slots)
(emit-get-slot slots index 'trap))))
(flatten-lap
(opcode :label 'trap)
(emit-miss 'miss-fn))
nil
(and (null class-slot-p) (list slots)))))))
(defun emit-one-index-writers (class-slot-p)
(declare (type boolean class-slot-p))
(let ((arglist (list (dfun-arg-symbol 0) (dfun-arg-symbol 1))))
(generating-lap '(field cache-vector mask size index miss-fn)
arglist
(with-lap-registers ((slots vector))
(emit-dlap arglist
'(t standard-instance)
'trap
(with-lap-registers ((index index))
(flatten-lap
(opcode :move (operand :cvar 'index) index)
(if class-slot-p
(emit-set-class-slot index (dfun-arg-symbol 0) slots)
(emit-set-slot slots index (dfun-arg-symbol 0)))))
(flatten-lap
(opcode :label 'trap)
(emit-miss 'miss-fn))
nil
(and (null class-slot-p) (list nil slots)))))))
(defun emit-n-n-readers ()
(let ((arglist (list (dfun-arg-symbol 0))))
(generating-lap '(field cache-vector mask size miss-fn)
arglist
(with-lap-registers ((slots vector)
(index index))
(emit-dlap arglist
'(standard-instance)
'trap
(emit-get-slot slots index 'trap)
(flatten-lap
(opcode :label 'trap)
(emit-miss 'miss-fn))
index
(list slots))))))
(defun emit-n-n-writers ()
(let ((arglist (list (dfun-arg-symbol 0) (dfun-arg-symbol 1))))
(generating-lap '(field cache-vector mask size miss-fn)
arglist
(with-lap-registers ((slots vector)
(index index))
(flatten-lap
(emit-dlap arglist
'(t standard-instance)
'trap
(emit-set-slot slots index (dfun-arg-symbol 0))
(flatten-lap
(opcode :label 'trap)
(emit-miss 'miss-fn))
index
(list nil slots)))))))
(defun emit-checking (metatypes applyp)
(let ((dlap-lambda-list (make-dlap-lambda-list metatypes applyp)))
(generating-lap '(field cache-vector mask size function miss-fn)
dlap-lambda-list
(emit-dlap (remove '&rest dlap-lambda-list)
metatypes
'trap
(with-lap-registers ((function t))
(flatten-lap
(opcode :move (operand :cvar 'function) function)
(opcode :jmp function)))
(with-lap-registers ((miss-function t))
(flatten-lap
(opcode :label 'trap)
(opcode :move (operand :cvar 'miss-fn)